/**
 * 医生表格初始化
 */
var DoctorTable = {
    id: "DoctorChangePriceTable",	//表格id
    seItem: null,		//选中的条目
    table: null,
    layerIndex: -1
};

/**
 * 初始化表格的列
 */
DoctorTable.initColumn = function () {
    var columns = [
        {title: 'id', field: 'id', visible: false, align: 'center', valign: 'middle'},
        {title: 'reservationsId', field: 'reservationsId', visible: false, align: 'center', valign: 'middle'},
        {title: '病历号', field: 'medicalRecordNumber', align: 'center', valign: 'middle', sortable: true},
        {title: '客户状态', field: 'customerStatus', align: 'center', valign: 'middle', sortable: true},
        {title: '客户姓名', field: 'customerName', align: 'center', valign: 'middle', sortable: true},
        {title: '电话', field: 'customerPhone', align: 'center', valign: 'middle', sortable: true},
        {
            title: '性别', field: 'customerSex', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (value == 1) {
                    return "男";
                } else if (value == 2) {
                    return "女"
                }else{return "未知"}
            }
        },
        {title: '年龄', field: 'customerAge', align: 'center', valign: 'middle', sortable: true},
        {title: 'TC', field: 'tcName', align: 'center', valign: 'middle', sortable: true},
        {title: '医生', field: 'doctor', align: 'center', valign: 'middle', sortable: true},
         {title: '项目名称', field: 'payServiceName', align: 'center', valign: 'middle', sortable: true},
        {title: '项目个数', field: 'payServiceNum', align: 'center', valign: 'middle', sortable: true},
        {title: '折后总价', field: 'foldingPay', align: 'center', valign: 'middle', sortable: true},
        {
            title: '划价操作', field: 'checkStatus', align: 'center', valign: 'middle', sortable: true,
            formatter: function (value, row, index) {
                if (row.checkStatus == '1') {
                    return "<label style='color: green'>已划价</label>"
                } else{
                    return "<a href='javascript:;' onclick='DoctorTable.huaPrice(" + '"' + row.id + '"' + ")'>[划价]</a>"
                }

            }
        },
    ]
    return columns;
};


/**
 * 医生划价
 * @param id
 */
DoctorTable.huaPrice = function (id) {
    $.ajax({
        url: Feng.ctxPath + "/doctorLooked/hua_price/"+id ,
        success: function (data) {
            alert("划价成功");
            DoctorTable.search();//操作成功后刷新数据
        },
        error: function (data) {
            alert("划价失败");
        }
    })
}

/**
 * 查询预约客户列表
 */
DoctorTable.search = function () {
    DoctorTable.table.refresh();
};

$(function () {
    var defaultColunms = DoctorTable.initColumn();
    var reservationsId =$("#reservations_id").val();
    var table = new BSTable(DoctorTable.id, "/doctorLooked/changePriceTable/"+reservationsId, defaultColunms);
    table.setPaginationType("client");//客户端分页
    DoctorTable.table = table.init();
    DoctorTable.search();
});
